-> root -> language -> ::language::perl
Everything regarding the Perl programming language, as you can find on http://www.perl.org
Notes on this page:

Sys::Syslog error '/dev/conslog not writable' and perl leaving...
[22]

Ok, symptoms:

  • Your script dies with an error similar to the following:
      stream /dev/conslog is not writable at ...
      console is not writable at ...
      no connection to syslog available ...
      

  • If you run your script as 'root', everything works perfectly, while as a normal user syslog does not seem to work... no! users should be allowed to log messages! it's not a privileged operation! don't ever think about that!

  • 'logger' or similar commands seems to work and log fine, without troubles, both as users and administrators... I used something like:
    $ logger -t test -p local0.notice 'test'
    $ su
    # logger -t test -p local0.notice 'test'
          

Well, you should:
  • make sure syslog is properly configured and running and that devices/unix sockets have the correct permissions, by checking that the above command ('logger ...') works correctly.

  • make sure your code calls the 'openlog' functions once and only once. On my perl 5.8.4 Linux System, I had two different modules calling the 'openlog' function... and well, as 'root', everything worked just fine, but as soon as I switched to an unprivileged user, the second 'openlog' caused the error described.

Other workarounds? Have I been a fool? Am I totally wrong? well, removing the second openlog call just solved my problems, so, let's not bother about investigating what's going wrong...

This note is available in the following categories:

PERL5LIB, PERLLIB, perl -I and self contained scripts
[23]

Ever had an error like:
$ ./my-perl-script
Can't locate ... in @INC (@INC contains: ...) at ... line ... .
BEGIN failed--compilation aborted at ... line ... .
Well, this often happens when you have a directory with your perl scripts and its own modules, which you have not installed yet.

A good solution is usually to go in the lib/ directory of the tarball, or the directory containing the name of the missing module. For example, if the message above complains about missing RBC/XML.pm, with something like:
Can't locate RBC/XML.pm in @INC (@INC ...
You can simply:
$ find . -type d -name 'RBC'
./lib/RBC
$ cd lib
$ ../my-perl-script
Well, if you can't change directory, or you get another error about another missing library, you can simply use the PERL5LIB or PERLLIB environment variable, with something like:
$ PERL5LIB=/home/.../lib/ ./my-perl-script
or 
$ export PERL5LIB=/home/.../lib/ 
$ ./my-perl-script
Note that if you use an absolute path in PERL5LIB, you can run my-perl-script from anywhere on your file system. Instead of PERL5LIB you can always use PERLLIB, or the -I parameter to the perl executable, with something like:
 $ perl -I/home/.../lib/ ./my-perl-script
PERLLIB and PERL5LIB are ignored in case the script is somewhat privileged. To know more about all of this, just run:
  $ man perlrun
 
and search '-I' or 'PERL5LIB'.

This note is available in the following categories:

Error: Can't locate object method "new" via package "XXX" (perhaps you forgot to load "XXX"?) at YYYY.
[40]

Either:

  • Check the documentation of the module one more time, you are using it the wrong way.

  • If you wrote the module yourself, you forgot to add the line:
         package Full::Name::of::module::XXX;
         

This note is available in the following categories:

Being lazy with logging in perl
[41]

When using Sys::Syslog, you don't have to use LOG_DAEMON, LOG_WARNING or LOG_WHATEVER. You can just pass the string 'warning', 'daemon' and so on. I have very bad memory, and this helps :)
This note is available in the following categories:

Printing on a file descriptor contained in a hash
[43]

It's easy, just use something like:
   print {$config{'pippo'}} 'whatever you want to print';
 
Note that $config is a hash (%config), and the outher brackets are there to tell perl that it is indeed the file descriptor to output stuff too, and not what we want to output. If you don't use those brakets, like:
   print $config{'pippo'} 'whatever you want to print';
 
most likely, you'll get an error like:
   String found where operator expected at ./xxx.pl line yyy, near "} 'whatever'"
   (Missing operator before  'whatever'?)
 
This note is available in the following categories:
Generated by CRON on 2012/02/14 at 06:26:35.